package com.serverlite.framework.dao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SQL {

    public static String loadSql(String name) {
        StringBuffer buffer = new StringBuffer();
        BufferedReader br = new BufferedReader(new InputStreamReader(
                SQL.class.getResourceAsStream("/sql/"+name)));
        try {
            String line = null;
            while ((line = br.readLine()) != null) {
                buffer.append(line);
                buffer.append("\n");
            }
            if (buffer.lastIndexOf("\n") > 0) {
                buffer.deleteCharAt(buffer.lastIndexOf("\n"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return buffer.toString();
    }
}
